package com.yanqu.road.server.cmd.activity.springdraw;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SpringDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.springdraw.SpringDrawModule;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = SpringDrawProto.SpringDrawNextLevelReqMsg.class, respMsg = SpringDrawProto.SpringDrawNextLevelRespMsg.class)
@Cmd(code = Protocol.S_SPRING_DRAW_NEXT_LEVEL, desc = "花袭春意-进入下一关")
public class SpringDrawEnterNextLevelCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SpringDrawProto.SpringDrawNextLevelReqMsg reqMsg = SpringDrawProto.SpringDrawNextLevelReqMsg.parseFrom(packet.getBytes());
        SpringDrawProto.SpringDrawNextLevelRespMsg.Builder respMsg;
        try {
            //浇灌
            respMsg = player.getModule(SpringDrawModule.class).enterNextLevel(reqMsg);
        } catch (BusinessException e) {
            respMsg = SpringDrawProto.SpringDrawNextLevelRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(Protocol.U_SPRING_DRAW_NEXT_LEVEL, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
